<?php
class ModelPageCommon extends Model{

	public function getVisits($data) {
	
			$sql = "SELECT * FROM " . DB_PREFIX . " visit"; 
		
			if(isset($data["ip"])){
				$sql.=" where ip='".$data["ip"]."'";
			}
			
			$sql.=" order by date_added desc ";
		
			if (isset($data['start']) || isset($data['limit'])) {
				if ($data['start'] < 0) {
					$data['start'] = 0;
				}				

				if ($data['limit'] < 1) {
					$data['limit'] = 20;
				}	
			
				$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
			}
			
			$query = $this->db->query($sql);
		
			return $query->rows;
	}
	
	public function getTotalVisits($data) {
	
		$sql = "SELECT COUNT(*) AS total FROM " . DB_PREFIX . "visit ";
		
		if(isset($data["ip"])){
				$sql.=" where ip='".$data["ip"]."'";
		}

		$query = $this->db->query($sql);
		
		return $query->row['total'];
	}	
}
?>